import alsaaudio

class ALSADevice:
    def __init__(self, device_name: str):
        self.device = alsaaudio.PCM(device=device_name)

    def set_params(self, rate: int, channels: int):
        """设置参数"""
        self.device.setformat(alsaaudio.PCM_FORMAT_FLOAT_LE)
        self.device.setchannels(channels)
        self.device.setrate(rate)

    def write(self, data: bytes):
        """写入音频数据"""
        self.device.write(data)